package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.StudentDao;
import dao.TeacherDao;
import vo.Student;
import vo.Teacher;
//@WebServlet("/Tea_modifyServlet")
public class Tea_modifyServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String teano = (String)( ((Teacher)req.getSession().getAttribute("teacher")).getTeano());	
		String teaname = (String)req.getParameter("tea_name");
		String teapwd = (String)( ((Teacher)req.getSession().getAttribute("teacher")).getPassword());	
		String teasex=(String)req.getParameter("tea_sex");
		String teatitle=(String)req.getParameter("tea_title");
		String teatel = (String)req.getParameter("tea_tel");
		String teaemail=(String)req.getParameter("tea_email");
		String teadept=(String)req.getParameter("tea_dept");
		TeacherDao teadao=new TeacherDao();
		Teacher teacher;
		
		
		try {
			teacher = teadao.getTeacherByTeano(teano);
			teacher.setPassword(teapwd);
			teacher.setTeadept(teadept);
			teacher.setTeaemail(teaemail);
			teacher.setTeaname(teaname);
			teacher.setTeano(teano);
			teacher.setTeasex(teasex);
			teacher.setTeatel(teatel);
			teacher.setTitle(teatitle);
			teadao.updateTeacher(teacher);
			req.getSession().removeAttribute("teacher");
			req.getSession().setAttribute("teacher", teacher);
			req.getRequestDispatcher("/jsp/teacher/tea_form.jsp").forward(req, resp);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
